package com.wyb.controller;
import java.io.IOException;

import junitparams.JUnitParamsRunner;
import junitparams.Parameters;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wyb.entity.User;

/**
 * <p>User: 
 * <p>Date: 
 * <p>Version: 1.0
 */
@EnableAutoConfiguration
@RestController
@RequestMapping("/test")
@RunWith(JUnitParamsRunner.class)
public class TestController {

    @RequestMapping("/{id}")
    public User view(@PathVariable("id") Long id) {
        User user = new User();
        user.setId(id);
        user.setName("TEST,.slslslsjdfsadfjsadlkfsadf ");
        return user;
    }

    public static void main(String[] args) {
       SpringApplication.run(TestController.class);
    }
    
    @Test
    @Parameters({"11, true", "22, true" })
    public void personIsAdult(int age, boolean valid) throws Exception {
       if(valid){
    	   //this.run("http://localhost:8080/user/1");
    	   System.out.println("年龄="+this.run("http://localhost:8080/user/1"));
       }
    }
    

    OkHttpClient client = new OkHttpClient();
    String run(String url) throws IOException {
      Request request = new Request.Builder().url(url).build();
      Response response = client.newCall(request).execute();
      return response.body().string();
    }

}
